.\"
.\" FreeBSD pkg - a next generation package for the installation and maintenance
.\" of non-core utilities.
.\"
.\" Redistribution and use in source and binary forms, with or without
.\" modification, are permitted provided that the following conditions
.\" are met:
.\" 1. Redistributions of source code must retain the above copyright
.\"    notice, this list of conditions and the following disclaimer.
.\" 2. Redistributions in binary form must reproduce the above copyright
.\"    notice, this list of conditions and the following disclaimer in the
.\"    documentation and/or other materials provided with the distribution.
.\"
.\"
.\"     @(#)pkg.8
.\"
.Dd November 18, 2016
.Dt PKG-QUERY 8
.Os
.Sh NAME
.Nm "pkg query"
.Nd query information for installed packages
.Sh SYNOPSIS
.Nm
.Ao query-format Ac Ao pkg-name Ac
.Pp
.Nm
.Op Fl a
.Ao query-format Ac
.Nm
.Fl F Ao pkg-file Ac Ao query-format Ac
.Nm
.Fl e Ao evaluation-condition Ac Ao query-format Ac
.Nm
.Op Fl Cgix
.Ao query-format Ac Ao pattern Ac Ao ... Ac
.Pp
.Nm
.Op Cm --all
.Ao query-format Ac
.Nm
.Cm --file Ao pkg-file Ac Ao query-format Ac
.Nm
.Cm --evaluate Ao evaluation-condition Ac Ao query-format Ac
.Nm
.Op Cm --{case-sensitive,glob,case-insensitive,regex}
.Ao query-format Ac Ao pattern Ac Ao ... Ac
.Sh DESCRIPTION
.Nm
is used for displaying information about packages.
.Sh OPTIONS
The following options are supported by
.Nm :
.Bl -tag -width evaluate
.It Fl a , Cm --all
Match all packages from the database
.It Fl C , Cm --case-sensitive
Make the standard or the regular expression
.Fl ( x )
matching against
.Ar pkg-name
case sensitive.
.It Fl e , Cm --evaluate
Match packages using the given
.Ar evaluation-condition .
See
.Sx EVALUATION FORMAT
for details.
.It Fl F Ar pkg-file , Cm --file Ar pkg-file
Display information only for the package file
.Ar pkg-name .
.It Fl i , Cm --case-insensitive
Make the standard or regular expression
.Fl ( x )
matching against
.Ar pkg-name
case insensitive.
This is the default, unless modified by setting
.Ev CASE_SENSITIVE_MATCH
to true in
.Pa pkg.conf .
.It Fl g , Cm --glob
Treat
.Ao pattern Ac
as a glob pattern.
.It Fl x , Cm --regex
Treat
.Ao pattern Ac
as a regular expression according to the "modern" or "extended" syntax
of
.Xr re_format 7 .
.El
.Sh QUERY FORMAT
There are two types of keywords for the query format: the multiline and the
normal one.
Only one type of multiline pattern is accepted for a given query.
.Ss Normal patterns
.Bl -tag -width F1
.It Cm \&%n
Name of the matched package
.It Cm \&%v
Version of the matched package
.It Cm \&%o
Origin of the matched package
.It Cm \&%p
Prefix of the matched package
.It Cm \&%m
Maintainer of the matched package
.It Cm \&%c
Comment of the matched package
.It Cm \&%e
Description of the matched package
.It Cm \&%w
Home page of the matched package
.It Cm \&%V
Returns 0 if the package is not marked as
.Qq vital ,
and 1 is the package is marked
.Qq vital .
.It Cm \&%l
License logic of the matched package - nothing for single, & for AND, and | for OR
.It Cm \&%s Ns Op bh
The flat size of the matched package, where
.Cm b
is in bytes, and
.Cm h
is in human readable format.
.It Cm \&%a
Returns 1 if the matched package was automatically installed
as a dependency of another package, 0 otherwise.
The package can be automatically removed via
.Sq pkg autoremove
when this flag is set and no other package depends on it.
.It Cm \&%Q
Alternative architecture of the matches package
.It Cm \&%q
Architecture of the matched package
.It Cm \&%k
Returns 1 if the matched package is locked against modification or deletion, 0 otherwise
.It Cm \&%M
message contained in the matched package
.It Cm \&%t
Timestamp that the package was installed
.It Cm \&%R
The name of the repository from which the package was installed if
available, or
.Dq unknown-repository
otherwise.
.It Cm \&%\&? Ns Op drCFODLUGBbA
Returns 0 if the list is empty and 1 if the list has information to display.
.Bl -tag -width indent
.It Cm d
for dependencies
.It Cm r
for reverse dependencies
.It Cm C
for categories
.It Cm F
for files
.It Cm O
for options
.It Cm D
for directories
.It Cm L
for licenses
.It Cm U
for users
.It Cm G
for groups
.It Cm B
for required shared libraries
.It Cm b
for provided shared libraries
.It Cm A
for annotations
.El
.It Cm \&%# Ns Op drCFODLUGBbA
Returns the number of elements in the list
.Bl -tag -width indent
.It Cm d
for dependencies
.It Cm r
for reverse dependencies
.It Cm C
for categories
.It Cm F
for files
.It Cm O
for options
.It Cm D
for directories
.It Cm L
for licenses
.It Cm U
for users
.It Cm G
for groups
.It Cm b
for shared
.It Cm B
for required shared libraries
.It Cm b
for provided shared libraries
.It Cm A
for annotations
.El
.El
.Ss Multiline patterns
.Bl -tag -width F1
.It Cm \&%d Ns Op nov
Expands to the list of dependencies for the matched package, where
.Cm n
stands for the package name,
.Cm o
for the package origin, and
.Cm v
for the package version.
.It Cm \&%r Ns Op nov
Expands to the list of reverse dependencies for the matched package, where
.Cm n
stands for the package name,
.Cm o
for the package origin, and
.Cm v
for the package version.
.It Cm \&%C
Expands to the list of categories the matched package belongs to.
.It Cm \&%F Ns Op ps
Expands to the list of files of the matched package, where
.Cm p
stands for path, and
.Cm s
for sum.
.It Cm \&%D
Expands to the list of directories of the matched package.
.It Cm \&%O Ns Op kvdD
Expands to the list of options of the matched package, where
.Cm k
stands for option key,
.Cm v
for option value,
.Cm d
for option default value and
.Cm D
for option description.
Option default values and descriptions are optional metadata and may
be blank for certain packages.
.It Cm \&%L
Expands to the list of license(s) for the matched package.
.It Cm \&%U
Expands to the list of users needed by the matched package.
.It Cm \&%G
Expands to the list of groups needed by the matched package.
.It Cm \&%B
Expands to the list of shared libraries used by programs from the matched package.
.It Cm \&%b
Expands to the list of shared libraries provided by the matched package.
.It Cm \&%A Ns Op tv
Expands to the list of annotations for the matched package,
where
.Cm t
stands for the annotation tag, and
.Cm v
stands for the annotation value.
.El
.Sh EVALUATION FORMAT
Packages can be selected by using expressions comparing
.Ar Variables
(see below) to string or integer values.
The mode of comparison is specified by the
.Ar Operator
(also listed below).
Expressions can be combined using && (for and) and || (for or).
Parentheses can be used for grouping in the usual manner.
.Pp
String values are either any text not containing whitespace (possibly
followed by but not including whitespace) or any text enclosed in single or
double quotes.
.Ss Variables
.Bl -tag -width F1
.It Cm \&%n
Name of the package (type string)
.It Cm \&%o
Origin of the package (type string)
.It Cm \&%p
Prefix of the package (type string)
.It Cm \&%m
Maintainer of the package (type string)
.It Cm \&%c
Comment of the package (type string)
.It Cm \&%e
Description of the package (type string)
.It Cm \&%w
WWW address of the package (type string)
.It Cm \&%s
Flatsize of the package (type integer)
.It Cm \&%a
Automatic status of the package (type integer)
.It Cm \&%q
Architecture of the package (type string)
.It Cm \&%k
Locking status of the package (type integer)
.It Cm \&%M
Message of the package (type string)
.It Cm \&%t
Timestamp that the package was installed (type integer)
.It Cm \&%i
Additional information about the package (type string)
.It Cm \&%# Ns Op drCFODLUGBbA
Number of elements in the list of information (type integer).
See
.Cm %?
above for what information is used.
.El
.Ss Operators
.Bl -tag -width F1
.It Va var Cm ~ Ar glob
The string value of
.Va var
matches the given glob pattern.
.It Va var Cm !~ Ar glob
The string value of
.Va var
does not match the given glob pattern.
.It Va var Cm > Ns Oo = Oc Ar num
The numerical value of
.Va var
is greater than
.Op or equal to
the given number.
.It Va var Cm < Ns Oo = Oc Ar num
The numerical value of
.Va var
is less than
.Op or equal to
the given number.
.It Va var Cm = Ns Oo = Oc Ar num
The numerical value of
.Va var
is equal to the given number.
.It Va var Cm != Ar num
The numerical value of
.Va var
is not equal to the given number.
.El
.Sh ENVIRONMENT
The following environment variables affect the execution of
.Nm .
See
.Xr pkg.conf 5
for further description.
.Bl -tag -width ".Ev NO_DESCRIPTIONS"
.It Ev PKG_DBDIR
.It Ev CASE_SENSITIVE_MATCH
.El
.Sh FILES
See
.Xr pkg.conf 5 .
.Sh EXIT STATUS
.Ex -std
.Sh EXAMPLES
List all installed packages by name-version:
.Dl $ pkg query %n-%v
.Pp
List all dependencies for a package by origin:
.Dl $ pkg query %do subversion
.Pp
List all dependencies by package name-version:
.Dl $ pkg query %dn-%dv subversion
.Pp
List all reverse dependencies for a package:
.Dl $ pkg query %ro perl
.Pp
List all files and their known checksums for a package:
.Dl $ pkg query '%Fp %Fs' perl
.Pp
List all files for all packages:
.Dl $ pkg query '%o: %Fp'
.Pp
List all packages with no reverse dependencies:
.Dl $ pkg query -e '%#r = 0' %o
.Pp
List non-automatic packages:
.Dl $ pkg query -e '%a = 0' %o
.Pp
List automatic packages:
.Dl $ pkg query -e '%a = 1' %o
.Pp
List unmaintained packages:
.Dl $ pkg query -e '%m = ports@FreeBSD.org' %o
.Sh SEE ALSO
.Xr pkg_printf 3 ,
.Xr pkg_repos 3 ,
.Xr pkg-repository 5 ,
.Xr pkg.conf 5 ,
.Xr pkg 8 ,
.Xr pkg-add 8 ,
.Xr pkg-alias 8 ,
.Xr pkg-annotate 8 ,
.Xr pkg-audit 8 ,
.Xr pkg-autoremove 8 ,
.Xr pkg-backup 8 ,
.Xr pkg-check 8 ,
.Xr pkg-clean 8 ,
.Xr pkg-config 8 ,
.Xr pkg-create 8 ,
.Xr pkg-delete 8 ,
.Xr pkg-fetch 8 ,
.Xr pkg-info 8 ,
.Xr pkg-install 8 ,
.Xr pkg-lock 8 ,
.Xr pkg-register 8 ,
.Xr pkg-repo 8 ,
.Xr pkg-rquery 8 ,
.Xr pkg-search 8 ,
.Xr pkg-set 8 ,
.Xr pkg-shell 8 ,
.Xr pkg-shlib 8 ,
.Xr pkg-ssh 8 ,
.Xr pkg-stats 8 ,
.Xr pkg-update 8 ,
.Xr pkg-updating 8 ,
.Xr pkg-upgrade 8 ,
.Xr pkg-version 8 ,
.Xr pkg-which 8
